package com.hwd.srb.core.enmu;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Arrays;

/**
 * @author 黄伟东/Victor
 * @date 2022/3/25 17:30
 * @Description 还款方式枚举类
 */
@NoArgsConstructor
@AllArgsConstructor
@Getter
public enum ReturnMethodEnum {

    EQUALITY_CORPUS_AND_INTEREST(1, "等额本息"),
    EQUALITY_CORPUS(2, "等额本金"),
    PER_MONTH_INTEREST_AND_ONCE_CORPUS(3, "每月还息一次还本"),
    ONCE_CORPUS_AND_INTEREST(4, "一次还本还息"),
    ;

    @EnumValue
    private Integer value;

    @JsonValue
    private String returnMethod;

    @Override
    public String toString() {
        return this.returnMethod;
    }

    public static String getReturnMethodByValue(int value) {
        return Arrays.stream(ReturnMethodEnum.values())
                .filter(i -> i.getValue() == value)
                .map(ReturnMethodEnum::getReturnMethod)
                .findFirst()
                .orElse("");
    }
}
